<template>
  <div class="outer-box">
    <div class="user-menu-container">
      <div class="user-avatar"></div>
      <div class="user-menu">
        <a href="#" class="menu-item active" @click="goToUserCenter">个人主页</a>
        <a href="#" class="menu-item" @click="goToCreateCenter">创作平台</a>
        <a href="#" class="menu-item logout" @click="logout">退出登录</a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserInfo",
  components: {},
  data() {
    return {

    }
  },
  methods: {
    goToUserCenter() {
      this.$router.push({
        path: '/userCenter',
      })
    },
    goToCreateCenter() {
      this.$router.push({
        path: '/user',
      })
    },
    logout() {
      this.$store.dispatch('user/logout')
    }
  }
}
</script>

<style scoped>
.outer-box {
  width: 93.5px;
  height: 36.8px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.user-menu-container {
  position: relative;
}

.user-avatar {
  width: 36.8px;
  height: 36.8px;
  border-radius: 50%;
  background-image: url('https://picsum.photos/45/45?random=0');
  background-size: cover;
  background-position: center;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 101;
}

.user-menu {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 100%;
  width: 93.5px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 100;
  display: none;
  text-align: center;
  padding-top: 10px;
  margin-top: -10px;
}

.user-menu::before {
  content: '';
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 10px;
  background: transparent;
}

.user-menu-container:hover .user-menu,
.user-menu:hover {
  display: block;
}

.menu-item {
  padding: 12px 16px;
  display: block;
  color: #333;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  text-align: center;
}

.menu-item:hover {
  background-color: #f5f5f5;
}

.menu-divider {
  height: 1px;
  background-color: #eee;
  margin: 6px 0;
}
</style>